layui.define(['element'],function(exports){
    var $ = layui.$;
    $('.input-field').on('change',function(){
        var $this = $(this),
            value = $.trim($this.val()),
            $parent = $this.parent();

        if(value !== '' && !$parent.hasClass('field-focus')){
            $parent.addClass('field-focus');
        }else{
            $parent.removeClass('field-focus');
        }
    })
    exports('login');
});
var vm = new Vue({
    el:'#vm',
    data:{
        username:undefined
        ,password:undefined
        ,verifyCode:undefined
        ,img:undefined
        ,tip:"看不清?刷新试试"
    },
    created:function(){
        this.refreshCode();
    },
    methods: {
        refreshCode(){
            this.img="/sys/user/getCode?id="+Math.random();
        },
        userLogin(){
            $.ajax({
                url:'/sys/user/login',
                dataType:"json",
                type:'post',
                data:{
                    password: vm.password,
                    username: vm.username,
                    verifyCode:vm.verifyCode
                },
                success:(res)=>{
                    console.log(res)
                    if (res.code==200){
                        window.location.href = 'index.html';
                    }else {
                        this.$message({
                            message:res.msg,
                            type:'warning'
                        })
                    }
                },
                error:(res)=>{
                    this.$message({
                        message:JSON.parse(res.responseText).message,
                        type:'warning'
                    })
                }
            })
        }
    }
})

